package net.wanglu.www.spdr.rule;

import java.util.HashMap;
import java.util.regex.Pattern;

public class GuardianRule implements Rule {

	/**
	 * Guardian站点中，表示标签的class属性
	 */
	public static final String TAG_CLASS = "class";
	/**
	 * Guardian站点中，表示标签的id属性
	 */
	public static final String TAG_ID = "id";
	/**
	 * Guardian站点中，表示标签的itemprop属性
	 */
	public static final String TAG_ITEMPROP = "itemprop";
	/**
	 * Guardian站点中，表示标签的rel属性
	 */
	public static final String TAG_REL = "rel";
	
	@Override
	public HashMap<String, String> abstractTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(GuardianRule.TAG_ID, "stand-first");
		return map;
	}

	@Override
	public String charSet() throws Exception {
		// TODO Auto-generated method stub
		return "UTF-8";
	}

	@Override
	public HashMap<String, String> dateTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(Rule.SON+Rule.ELEMENT_NAME, "time");
		map.put(Rule.FATHER+GuardianRule.TAG_CLASS, "publication");
		return map;
	}

	@Override
	public String homeUrl() throws Exception {
		// TODO Auto-generated method stub
		return "http://www.guardian.co.uk";
	}

	@Override
	public HashMap<String, String> targetTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(GuardianRule.TAG_ID, "article-body-blocks");
		return map;
	}

	@Override
	public HashMap<String, String> textTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(Rule.SON+Rule.ELEMENT_NAME, "p");
		map.put(Rule.FATHER+GuardianRule.TAG_ID, "article-body-blocks");
		return map;
	}

	@Override
	public HashMap<String, String> titleTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(GuardianRule.TAG_ITEMPROP, "name");
		return map;
	}

	@Override
	public Pattern validUrlRule() throws Exception {
		String regex = "/201\\d/[a-z]+/[01]\\d/";
		Pattern pattern = Pattern.compile(regex);
		return pattern;
	}

	@Override
	public HashMap<String, String> authorTagRule() throws Exception {
		// TODO Auto-generated method stub
		HashMap<String, String> map = new HashMap<String, String>(4);
		map.put(GuardianRule.TAG_REL, "author");
		return map;
	}

	@Override
	public HashMap<String, String> crossHeadTagRule() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Pattern rejectedUrlRule() throws Exception {
		String regex = "radio-and-tv|china";
		Pattern pattern = Pattern.compile(regex);
		return pattern;
	}

}
